package com.copa.l953;

/**
 * @author copa
 * @createDate 2022-09-02 14:56
 * @function 暴力法
 */
public class Test1 {

    public boolean isAlienSorted(String[] words, String order) {
        String word1, word2;
        for (int i = 0; i < words.length - 1; i++) {
            word1 = words[i];
            word2 = words[i + 1];
            if (!word1.equals(word2)) {
                for (int j = 0; j < word1.length(); j++) {
                    if (j >= word2.length()) {
                        return false;
                    }
                    int str1 = order.indexOf(word1.charAt(j));
                    int str2 = order.indexOf(word2.charAt(j));
                    if (str1 < str2) {
                        break;
                    }
                    if (str1 > str2) {
                        return false;
                    }
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        //["fxasxpc","dfbdrifhp","nwzgs","cmwqriv","ebulyfyve","miracx","sxckdwzv","dtijzluhts","wwbmnge","qmjwymmyox"]
        //"zkgwaverfimqxbnctdplsjyohu"
        String[] words = {"fxasxpc","dfbdrifhp","nwzgs","cmwqriv","ebulyfyve","miracx","sxckdwzv","dtijzluhts","wwbmnge","qmjwymmyox"};
        String order = "zkgwaverfimqxbnctdplsjyohu";
//        String[] words = {"hello","leetcode"};
//        String order = "hlabcdefgijkmnopqrstuvwxyz";
        System.out.println(new Test1().isAlienSorted(words, order));
    }
}
